package com.bw.a3_27zk

import android.util.Log
import androidx.fragment.app.Fragment
import com.bw.a3_27zk.adapter.FragmentAdapter
import com.bw.a3_27zk.databinding.ActivityMainBinding
import com.bw.a3_27zk.fg.BlankFragment1
import com.bw.a3_27zk.fg.BlankFragment2
import com.bw.a3_27zk.fg.BlankFragment3
import com.bw.base.mvvm.BaseViewActivity
import kotlin.math.log

class MainActivity : BaseViewActivity<ActivityMainBinding>() {
    var list = ArrayList<Fragment>()
    lateinit var fragmentAdapter: FragmentAdapter

    override fun initView() {

        list.add(BlankFragment1())
        list.add(BlankFragment2())
        list.add(BlankFragment3())
        fragmentAdapter = FragmentAdapter(this, list)
        binding.vp.adapter = fragmentAdapter
        //上下联动
        binding.vp.registerOnPageChangeCallback(object :
            androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback() {
            override fun onPageSelected(position: Int) {
                super.onPageSelected(position)
                when (position) {
                    0 -> binding.rb1.isChecked = true
                    1 -> binding.rb2.isChecked = true
                    2 -> binding.rb3.isChecked = true
                }
            }
        })
        binding.rg.setOnCheckedChangeListener { group, checkedId ->
            when (checkedId) {
                R.id.rb1 -> binding.vp.currentItem = 0
                R.id.rb2 -> binding.vp.currentItem = 1
                R.id.rb3 -> binding.vp.currentItem = 2
            }
        }



        findEvenNumbers()
        val person = Person("张三", 20, "123@qq.com")
        if (isAdult(person)){
            Log.d("lll",person.toString() )
        } else{
            Log.d("lll",person.toString())
        }
        lll()
        meth {
            Log.d("lll","111")
        }


    }


    override fun initData() {

    }
    fun findEvenNumbers() {
        val numbers = mutableListOf<Int>(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
        numbers.filter {
            it % 2 == 0
        }.forEach {
            Log.d("lll", "升序排列后是$it")

        }

    }



    override fun getLayoutId(): Int = R.layout.activity_main
}

fun lll(){
    //循环添加7的倍数
    val list = mutableListOf<Int>()

    for (i in 1..50){
        if (i%7 == 0){
            list.add(i)
        }
    }
    Log.d("lll",list.toString())
}

fun isAdult(person: Person): Boolean {
    return person.age >= 18
}
//19.写一个函数meth，参数为匿名函数（Int）->Unit,调用函数meth，并把结果输出
fun meth(block:(Int)->Unit){

  block(19)
}
data class Person(val name:String,val age:Int,val email:String)

